package batchProcess;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;

import java.util.ArrayList;
import java.util.List;
//把大的消息分裂成若干个小的消息
public class Test {
    public static void main(String[] args) throws Exception{


        DefaultMQProducer producer = new DefaultMQProducer("batchProducer");
        producer.setNamesrvAddr("192.168.1.153:9876");
        producer.start();

        String topic = "BatchTest";
        List<Message> messages = new ArrayList<>();
        messages.add(new Message(topic, "TagA", "OrderID001", new byte[1024*1024*4]));
        messages.add(new Message(topic, "TagA", "OrderID002", new byte[1024*1024*1]));
        messages.add(new Message(topic, "TagA", "OrderID003", new byte[1024*1024*1]));

        ListSplitter splitter = new ListSplitter(messages);
        while (splitter.hasNext()) {
            try {
                List<Message> listItem = splitter.next();
                producer.send(listItem);
            } catch (Exception e) {
                e.printStackTrace();
                //处理error
            }
        }
    }

}
